package com.cwl.result;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.cwl.domain.Questions;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;

public class AjaxResultQuestion implements Result{
	public void execute(ActionInvocation invocation) throws Exception {
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("utf-8");
		Questions questions = (Questions) ActionContext.getContext().getValueStack().peek();
		PrintWriter out = response.getWriter();
		out.print("<div><h3><label for='answerx'>"+questions.getQuestion()+"</label></h3></div>");
		if(questions.getAnswerA()!=null){
			out.println("<input type='checkbox' name='selcet' id='answera' value='a' /><label for='answera'>"+questions.getAnswerA()+"</label><br/>");
			out.println("<input type='checkbox' name='selcet' id='answerb' value='b' /><label for='answerb'>"+questions.getAnswerB()+"</label><br/>");
			out.println("<input type='checkbox' name='selcet' id='answerc' value='c' /><label for='answerc'>"+questions.getAnswerC()+"</label><br/>");	
			out.println("<input type='checkbox' name='selcet' id='answerd' value='d' /><label for='answerd'>"+questions.getAnswerD()+"</label><br/>");			
			if(questions.getAnswerE()!=null){
				out.println("<input type='checkbox' name='selcet' id='answere' value='e' /><label for='answere'>"+questions.getAnswerE()+"</label><br/>");	
			}
			if(questions.getAnswerF()!=null){
				out.println("<input type='checkbox' name='selcet' id='answerf' value='f' /><label for='answerf'>"+questions.getAnswerF()+"</label><br/>");			
			}
		}else{
			out.println("<input type='text' name='selcet' checked='checked'  /><br/>");	
		}
		out.flush();
		out.close();
	}
}
